<template>
  <el-dialog
    title="添加接口"
    :visible.sync="dialogFormVisible"
    :before-close="handleClose"
    width="30%"
  >
    <el-form>
      <el-form-item label="分类名称：" :label-width="formLabelWidth">
        <el-select v-model="value" placeholder="请选择" size="mini">
          <el-option
            v-for="item in apiSuiteList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="接口名称：" :label-width="formLabelWidth">
        <el-input v-model="apiName" autocomplete="off" size="mini"></el-input>
      </el-form-item>
      <el-form-item label="接口路径：" :label-width="formLabelWidth">
        <el-input v-model="path" autocomplete="off" size="mini"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="gb()" size="mini">取 消</el-button>
      <el-button type="primary" @click="dj()" size="mini">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    dialogFormVisible: {
      type: Boolean,
    },
    apiSuiteId:{
        type: Number,
    }
  },
  watch:{
      apiSuiteId:function(id){
          this.value=id
      }
  },
  data() {
    return {
      value: "",
      apiSuiteList: "",
      apiName:"",
      path:"",
      formLabelWidth:"120px",
    };
  },
  created() {
    this.$api
      .apiSuiteList({
        projectId: this.$store.getters.getProjectId,
      })
      .then((res) => {
        console.log("apiSuite",res)
        this.apiSuiteList = res.data;

      })
      .catch((err) => {
        console.log(err);
      });

  },
  methods: {
    dj() {
      this.$api
        .apiAdd({
          name: this.apiName,
          path: this.path,
          projectId: this.$store.getters.getProjectId,
          apiSuiteId:this.value
        })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
      this.$emit("changeAddApiPage");
    },
    gb() {
      (this.apiName = ""),
        (this.path = ""),
        this.$emit("changeAddApiPage");
    },
    handleClose(done) {
      (this.apiName = ""),
        (this.path = ""),
        this.$emit("changeAddApiPage");
    },
  },
};
</script>
